<template>
  <div class></div>
</template>
<script>
import axios from "@/utils/requestdp";
import dayjs from "dayjs";

export default {
  name: "APIqueryDbzonghaoreliangnum",
  components: {},
  data() {
    return {};
  },
  computed: {
    ishistory: function () {
      return this.$store.state.daping.ishistorytime;
    },
    timerangarr: function () {
      return this.$store.state.daping.timepick;
    },
  },
  watch: {},
  mounted() {
    this.watchEvent();
  },
  methods: {
    watchEvent() {
      //先清除定时任务
      if (
        this.$store.state.daping.intervalArr["APIqueryDbzonghaoreliangnum"] !=
        undefined
      ) {
        return;
      }

      this.loadData();
      let interval = setInterval(() => {
        this.loadData();
      }, this.$root.setting.data.interval);
      this.$store.state.daping.intervalArr["APIqueryDbzonghaoreliangnum"] = [
        { interval: interval },
      ];
    },
    loadData() {
      // let day = dayjs().format("YYYY-MM-DD");

      let n_tmp = this.$store.state.daping.bigScreen;
      if (n_tmp == {} || n_tmp == []) {
        return;
      }
      let g_bigscreen_data_arr = n_tmp.filter((item) => {
        if (item.attrName == "start_date") {
          return true;
        }
      });

      if (g_bigscreen_data_arr.length != 1) {
        return;
      }

      let sday = g_bigscreen_data_arr[0].attrValue;

      // let day = "2020-10-16";
      let day = dayjs().format("YYYY-MM-DD");
      let st = dayjs(sday + " 00:00:00").unix();
      let et = dayjs(day + " 23:59:59").unix();

      let queryJson = {
        queries: [
          {
            metric: "id,sa_006qc",
            schema: "daily",
          },
        ],
        endTime: et,
        startTime: st,
        table: "pipenet",
        orderBy: "aligntime",
        search: "id=0",
      };

      let st1 = dayjs(day + " 00:00:00").unix();
      let et1 = dayjs(day + " 23:59:59").unix();

      let queryJson1 = {
        endTime: et1,
        queries: [
          {
            metric: "id,sa_006qc",
            schema: "dwb",
          },
        ],
        startTime: st1,
        table: "pipenet_m",
        type: "history",
        needType: false,
        orderBy: "aligntime",
        search: "id=0",
        limit: 1,
      };

      let req1 = axios.post("/open/queryDb", queryJson);
      let req2 = axios.post("/open/queryDb", queryJson1);

      Promise.all([req1, req2]).then((res) => {
        //如果有则获取200中的结果
        if (res[0].code == 200 && res[1].code == 200) {
          if (res[0].data[0] && res[1].data[0]) {
            this.$store.state.daping.zonghaoreliang = Number(res[0].data[0]['sa_006qc']) + Number(res[1].data[0]['sa_006qc'])
          }

        }
      });
    },
  },
};
</script>
<style lang='scss' scoped>
</style>